package com.zmn.mcc.admin.controller.staff.subarea;

import com.zmn.common.utils.number.NumberUtil;
import com.zmn.mcc.common.enums.SubAreaEnum;
import com.zmn.mcc.model.entity.staff.subarea.McSubAreaRelate;
import com.zmn.mcc.model.entity.staff.subarea.McSubAreaRelateQuery;
import com.zmn.mcc.services.interfaces.subarea.McSubAreaRelateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;


/**
 * 员工-片区-关联表基础查询Controller
 *
 * @author jiafei
 * @since 2022/07/18 14:22
 */
@Slf4j
@RestController
@RequestMapping("/staff/subarea")
public class McSubAreaRelateListController {

    @Resource
    private McSubAreaRelateService mcSubAreaRelateService;

    /**
     * 描述: 查询列表
     *
     * @author jiafei
     * @since 2022/07/18 14:22
     */
    @RequestMapping("/list")
    public ModelAndView list(McSubAreaRelateQuery query) {

        List<McSubAreaRelate> items = mcSubAreaRelateService.listPageByQuery(query);

        ModelAndView mv = new ModelAndView("channel/mcsubarearelate/list");
        mv.addObject("items", items);
        mv.addObject("vo", query);

        return mv;
    }

    /**
     * 描述: 详情
     *
     * @author jiafei
     * @since 2022/07/18 14:22
     */
    @RequestMapping("/addEditView")
    public ModelAndView addEditView(@RequestParam(value = "staffId") Integer staffId) {

        McSubAreaRelate mcSubAreaRelate;
        if (NumberUtil.isNullOrZero(staffId)) {
            mcSubAreaRelate = new McSubAreaRelate();
        } else {
            mcSubAreaRelate = mcSubAreaRelateService.findByStaffId(staffId);
        }
        ModelAndView mv = new ModelAndView("staff/bind_sub_area");
        mv.addObject("obj", mcSubAreaRelate);
        mv.addObject("subAreaOption", SubAreaEnum.listOption());
        mv.addObject("staffId", staffId);

        return mv;
    }

}
